package com.jswlw.service.biz.log.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jswlw.dao.biz.log.LogDevOptMapper;
import com.jswlw.entity.biz.DevInfo;
import com.jswlw.entity.biz.log.LogDevOpt;
import com.jswlw.service.biz.DevInfoService;
import com.jswlw.service.biz.log.LogDevOptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Service
public class LogDevOptServiceImpl implements LogDevOptService {
    @Autowired
    LogDevOptMapper mapper;
    @Autowired
    DevInfoService devInfoService;

    @Override
    public void add(LogDevOpt logDevOpt) {
        if (Objects.isNull(logDevOpt.getDevId())) {
            DevInfo devInfo = devInfoService.find4Imei(logDevOpt.getImei());
            if (Objects.nonNull(devInfo)) {
                logDevOpt.setDevId(devInfo.getId());
            }
        }
        logDevOpt.setCreateTime(new Date());
        mapper.insertSelective(logDevOpt);
    }

    @Override
    public List<LogDevOpt> queryList(LogDevOpt filter) {
        return null;
    }

    @Override
    public Page<LogDevOpt> queryPage(LogDevOpt filter) {
        PageHelper.startPage(filter.getOffset(), filter.getLimit());
        return (Page<LogDevOpt>) mapper.queryList(filter);
    }
}
